

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
    <style>
    /* base */
    html,
    body,
    .container {
      width: 100%;
      height: 100%;
    }

    a,
    a:link,
    a:visited {
      text-decoration: none;
      color: inherit;
    }

    ul {
      list-style: none;
    }

    *,
    ::before,
    ::after {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    *:focus {
      outline: 0;
    }

    .container {
      display: flex;
      padding-top: 20px;
    }

    /* Nav */
    .container .doc-nav {
      position: fixed;
      height: 100%;
      margin: 0 30px 0 40px;
      width: 280px;
    }

    .doc-nav .nav-header {
      display: flex;
      align-items: center;
      box-sizing: border-box;
      background-color: rgb(240, 241, 242);
      height: 40px;
      padding: 16px;
      font-size: 18px;
      font-weight: 500;
      color: rgb(62, 64, 66);
      cursor: pointer;
    }

    .doc-nav .nav-content {
      height: calc(100% - 40px);
      overflow-y: auto;
      color: rgb(32, 34, 36);
    }

    .doc-nav .nav-content .nav-list,
    .doc-nav .nav-content .nav-sub-list {
      line-height: 1.5rem;
    }

    .doc-nav .nav-content .nav-label {
      display: inline-block;
      position: relative;
      padding: 2px 0 2px 20px;
      margin-bottom: 4px;
    }

    .doc-nav .nav-content .nav-sub-label {
      position: relative;
      padding: 2px 0 2px 40px;
      font-size: 14px;
    }

    .doc-nav .nav-content .nav-sub-label:hover {
      text-decoration: underline;
    }

    .doc-nav .nav-content .nav-list .nav-label.group::before {
      border-bottom: 0.25rem solid transparent;
      border-left: 0.25rem solid #6e7072;
      border-right: 0;
      border-top: 0.25rem solid transparent;
      content: '';
      display: block;
      height: 0;
      left: 0.5rem;
      position: absolute;
      top: 0.625rem;
      transition: transform 0.1s linear;
      width: 0;
    }

    .doc-nav .nav-content .nav-list .nav-label.group.active::before {
      transform: rotate(90deg);
    }

    /* doc content */
    .container .doc-content {
      position: fixed;
      height: 100%;
      width: calc(100% - 80px - 40px - 30px - 240px);
      right: 0%;
      overflow-y: auto;
    }

    .doc-title {
      border-bottom: 1px solid #dcdee0;
      font-size: 22px;
      margin: 8px 0 0;
      padding-bottom: 16px;
    }

    .doc-content h3 {
      font-size: 24px;
      font-weight: 600;
      margin: 24px 0;
    }

    .doc-content h4 {
      font-size: 22px;
      font-weight: 500;
      margin: 30px 0 8px;
    }

    .doc-content h4 span {
      color: #007d9c;
    }

    .doc-content .doc-declare {
      background-color: #fafafa;
      border-radius: 5px;
      border: 1px solid #ccc;
      font-size: 14px;
      overflow-x: auto;
      padding: 10px;
      tab-size: 4;
      line-height: 20px;
    }

    .doc-content .doc-comment {
      font-size: 16px;
      margin: 16px 0;
      line-height: 24px;
      word-break: break-word;
    }
  </style>

</head>
<body>
  <div class="container">
    <div class="doc-nav">
      <a href="#Documentation" class="nav-header">Documentation</a>
      <nav class="nav-content">
        <ul class="nav-list">
          <li>
            <a href="#includes" class="nav-label">Includes</a>
             
            <ul class="nav-sub-list">

              <li>
                <a href="#tuya_driver.h" class="nav-sub-label">tuya_driver.h</a>
              </li>
      
            </ul>
            
          </li>
          <li>
            <a href="#macros" class="nav-label">Macros</a>
             
            <ul class="nav-sub-list">

              <li>
                <a href="#__TUYA_SPI_H__" class="nav-sub-label">__TUYA_SPI_H__</a>
              </li>
      

              <li>
                <a href="#TUYA_SPI_CPHA" class="nav-sub-label">TUYA_SPI_CPHA</a>
              </li>
      

              <li>
                <a href="#TUYA_SPI_CPOL" class="nav-sub-label">TUYA_SPI_CPOL</a>
              </li>
      

              <li>
                <a href="#TUYA_SPI_MODE_MASK" class="nav-sub-label">TUYA_SPI_MODE_MASK</a>
              </li>
      

              <li>
                <a href="#tuya_spi_send_then_send(spi, send1, len1, send2, len2)" class="nav-sub-label">tuya_spi_send_then_send(spi, send1, len1, send2, len2)</a>
              </li>
      

              <li>
                <a href="#tuya_spi_send_then_recv(spi, send, len1, recv, len2)" class="nav-sub-label">tuya_spi_send_then_recv(spi, send, len1, recv, len2)</a>
              </li>
      

              <li>
                <a href="#tuya_spi_send(spi, buf, len)" class="nav-sub-label">tuya_spi_send(spi, buf, len)</a>
              </li>
      

              <li>
                <a href="#tuya_spi_recv(spi, buf, len)" class="nav-sub-label">tuya_spi_recv(spi, buf, len)</a>
              </li>
      
            </ul>
            
          </li>
          <li>
            <a href="#functions" class="nav-label">Functions</a>
             
            <ul class="nav-sub-list">

              <li>
                <a href="#tuya_spi_bus_add_device" class="nav-sub-label">tuya_spi_bus_add_device</a>
              </li>
      
            </ul>
            
          </li>
          <li>
            <a href="#vars" class="nav-label">Vars</a>
             
            <ul class="nav-sub-list">

              <li>
                <a href="#tuya_spi_bus_init" class="nav-sub-label">tuya_spi_bus_init</a>
              </li>
      

              <li>
                <a href="#tuya_spi_xfer" class="nav-sub-label">tuya_spi_xfer</a>
              </li>
      

              <li>
                <a href="#tuya_spi_xfer_msg" class="nav-sub-label">tuya_spi_xfer_msg</a>
              </li>
      

              <li>
                <a href="#tuya_spi_exchange" class="nav-sub-label">tuya_spi_exchange</a>
              </li>
      

              <li>
                <a href="#tuya_spi_control" class="nav-sub-label">tuya_spi_control</a>
              </li>
      

              <li>
                <a href="#tuya_spi_deinit" class="nav-sub-label">tuya_spi_deinit</a>
              </li>
      
            </ul>
            
          </li>
          <li>
            <a href="#consts" class="nav-label">Consts</a>
            
            <ul class="nav-sub-list">
            
            </ul>
            
          </li>
          <li>
            <a href="#types" class="nav-label">Types</a>
            
            <ul class="nav-sub-list">
            
            </ul>
            
          </li>
          <li>
            <a href="#typedefs" class="nav-label">Typedefs</a>
             
            <ul class="nav-sub-list">

              <li>
                <a href="#tuya_spi_port_t;
" class="nav-sub-label">tuya_spi_port_t;
</a>
              </li>
      

              <li>
                <a href="#tuya_spi_mode_t;
" class="nav-sub-label">tuya_spi_mode_t;
</a>
              </li>
      

              <li>
                <a href="#tuya_spi_databits_t;
" class="nav-sub-label">tuya_spi_databits_t;
</a>
              </li>
      

              <li>
                <a href="#tuya_spi_cs_mode_t;
" class="nav-sub-label">tuya_spi_cs_mode_t;
</a>
              </li>
      

              <li>
                <a href="#tuya_spi_cfg_t;
" class="nav-sub-label">tuya_spi_cfg_t;
</a>
              </li>
      

              <li>
                <a href="#tuya_spi_msg_t;
" class="nav-sub-label">tuya_spi_msg_t;
</a>
              </li>
      

              <li>
                <a href="#tuya_spi_bus_cfg_t;
" class="nav-sub-label">tuya_spi_bus_cfg_t;
</a>
              </li>
      

              <li>
                <a href="#tuya_spi_bus_t" class="nav-sub-label">tuya_spi_bus_t</a>
              </li>
      

              <li>
                <a href="#tuya_spi_ops_t;
" class="nav-sub-label">tuya_spi_ops_t;
</a>
              </li>
      

              <li>
                <a href="#tuya_spi_t;
" class="nav-sub-label">tuya_spi_t;
</a>
              </li>
      
            </ul>
            
          </li>
        </ul>
      </nav>
    </div>
    <div class="doc-content">
      <h2 id="Documentation" class="doc-title">Documentation</h2>
      <h3 id="includes">Includes</h3>
      

      <h4 id="tuya_driver.h"><span>tuya_driver.h</span></h4>
      <pre class="doc-declare"><code>#include "tuya_driver.h"
</code></pre>
      <pre class="doc-comment">#include "tuya_driver.h"
</pre>
      <h3 id="macros">Macros</h3>
      

      <h4 id="__TUYA_SPI_H__">Marco <span>__TUYA_SPI_H__</span></h4>
      <pre class="doc-declare"><code>#define __TUYA_SPI_H__
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="TUYA_SPI_CPHA">Marco <span>TUYA_SPI_CPHA</span></h4>
      <pre class="doc-declare"><code>#define TUYA_SPI_CPHA            (1 << 0)
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="TUYA_SPI_CPOL">Marco <span>TUYA_SPI_CPOL</span></h4>
      <pre class="doc-declare"><code>#define TUYA_SPI_CPOL            (1 << 1)
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="TUYA_SPI_MODE_MASK">Marco <span>TUYA_SPI_MODE_MASK</span></h4>
      <pre class="doc-declare"><code>#define TUYA_SPI_MODE_MASK       (TUYA_SPI_CPHA | TUYA_SPI_CPOL)
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="tuya_spi_send_then_send(spi, send1, len1, send2, len2)">Marco <span>tuya_spi_send_then_send(spi, send1, len1, send2, len2)</span></h4>
      <pre class="doc-declare"><code>#define tuya_spi_send_then_send(spi, send1, len1, send2, len2)             \
   do {                                                                   \
       tuya_spi_msg_t   msg[2];                                          \
       msg[0].send_buf = send1;                                           \
       msg[0].recv_buf = NULL;                                            \
       msg[0].length  = len1;                                            \
       msg[1].send_buf = send2;                                           \
       msg[1].recv_buf = NULL;                                            \
       msg[1].length  = len2;                                            \
       tuya_spi_xfer_msg(spi, msg, 2);                                    \
   } while (0)
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="tuya_spi_send_then_recv(spi, send, len1, recv, len2)">Marco <span>tuya_spi_send_then_recv(spi, send, len1, recv, len2)</span></h4>
      <pre class="doc-declare"><code>#define tuya_spi_send_then_recv(spi, send, len1, recv, len2)               \
   do {                                                                   \
       tuya_spi_msg_t   msg[2];                                          \
       msg[0].send_buf = send;                                            \
       msg[0].recv_buf = NULL;                                            \
       msg[0].length  = len1;                                            \
       msg[1].send_buf = NULL;                                            \
       msg[1].recv_buf = recv;                                            \
       msg[1].length  = len2;                                            \
       tuya_spi_xfer_msg(spi, msg, 2);                                    \
   } while (0)
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="tuya_spi_send(spi, buf, len)">Marco <span>tuya_spi_send(spi, buf, len)</span></h4>
      <pre class="doc-declare"><code>#define tuya_spi_send(spi, buf, len)                                       \
   tuya_spi_xfer(spi, buf, NULL, len)
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="tuya_spi_recv(spi, buf, len)">Marco <span>tuya_spi_recv(spi, buf, len)</span></h4>
      <pre class="doc-declare"><code>#define tuya_spi_recv(spi, buf, len)                                       \
   tuya_spi_xfer(spi, NULL, buf, len)
</code></pre>
      <pre class="doc-comment"></pre>
      <h3 id="functions">Functions</h3>
      

      <h4 id="tuya_spi_bus_add_device">Func <span>tuya_spi_bus_add_device</span></h4>
      <pre class="doc-declare"><code>int tuya_spi_bus_add_device (tuya_spi_bus_t *spi_bus, tuya_spi_t **spi, tuya_spi_cfg_t *cfg);</code></pre>
      <pre class="doc-comment">/**
 * @brief add device
 * 
 * @param[in] spi_bus refer to tuya_spi_bus_t
 * @param[out] spi refer to tuya_spi_t
 * @param[in] cfg refer to tuya_spi_cfg_t
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */</pre>
      <h3 id="vars">Vars</h3>
      

      <h4 id="tuya_spi_bus_init">Variable <span>tuya_spi_bus_init</span></h4>
      <pre class="doc-declare"><code>int tuya_spi_bus_init     (tuya_spi_bus_t *spi_bus);</code></pre>
      <pre class="doc-comment">/**
 * @brief spi init
 * 
 * @param[in] spi_bus refer to tuya_spi_bus_t
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */</pre>

      <h4 id="tuya_spi_xfer">Variable <span>tuya_spi_xfer</span></h4>
      <pre class="doc-declare"><code>int tuya_spi_xfer    (tuya_spi_t *spi, void *send_buf, void *recv_buf, uint32_t length);</code></pre>
      <pre class="doc-comment">/**
 * @brief spi transfer
 * 
 * @param[in] spi refer to tuya_spi_t
 * @param[in] send_buf used to send
 * @param[in] recv_buf used to recv
 * @param[in] length message length
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */</pre>

      <h4 id="tuya_spi_xfer_msg">Variable <span>tuya_spi_xfer_msg</span></h4>
      <pre class="doc-declare"><code>int tuya_spi_xfer_msg     (tuya_spi_t *spi, tuya_spi_msg_t *msg, uint8_t num);</code></pre>
      <pre class="doc-comment">/**
 * @brief spi xfer msg
 * 
 * @param[in] spi refer to tuya_spi_t
 * @param[in] msg refer to tuya_spi_msg_t
 * @param[in] num message number
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */</pre>

      <h4 id="tuya_spi_exchange">Variable <span>tuya_spi_exchange</span></h4>
      <pre class="doc-declare"><code>int tuya_spi_exchange     (tuya_spi_t *spi, uint16_t out, uint16_t *in);</code></pre>
      <pre class="doc-comment">/**
 * @brief spi exchange
 * 
 * @param[in] spi refer to tuya_spi_t
 * @param[in] out message send buf
 * @param[in] in message recv buf
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */</pre>

      <h4 id="tuya_spi_control">Variable <span>tuya_spi_control</span></h4>
      <pre class="doc-declare"><code>int tuya_spi_control     (tuya_spi_t *spi, uint8_t cmd, void *arg);</code></pre>
      <pre class="doc-comment">/**
 * @brief spi control
 * 
 * @param[in] spi refer to tuya_spi_t
 * @param[in] cmd control command
 * @param[in] arg command argument
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */</pre>

      <h4 id="tuya_spi_deinit">Variable <span>tuya_spi_deinit</span></h4>
      <pre class="doc-declare"><code>int tuya_spi_deinit    (tuya_spi_t *spi);</code></pre>
      <pre class="doc-comment">/**
 * @brief spi deinit
 * 
 * @param[in] spi refer to tuya_spi_t
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */</pre>
      <h3 id="consts">Consts</h3>
      
      <h3 id="types">Types</h3>
      
      <h3 id="typedefs">Typedefs</h3>
      

      <h4 id="tuya_spi_port_t;
">Typedef <span>tuya_spi_port_t;
</span></h4>
      <pre class="doc-declare"><code>typedef enum {
   TUYA_SPI0 = 1,
   TUYA_SPI1,
} tuya_spi_port_t;
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="tuya_spi_mode_t;
">Typedef <span>tuya_spi_mode_t;
</span></h4>
      <pre class="doc-declare"><code>typedef enum {
   TUYA_SPI_MODE0 = (0 | 0),                         // CPOL = 0, CPHA = 0
   TUYA_SPI_MODE1 = (0 | TUYA_SPI_CPHA),             // CPOL = 0, CPHA = 1
   TUYA_SPI_MODE2 = (TUYA_SPI_CPOL | 0),             // CPOL = 1, CPHA = 0
   TUYA_SPI_MODE3 = (TUYA_SPI_CPOL | TUYA_SPI_CPHA)  // CPOL = 1, CPHA = 1
} tuya_spi_mode_t;
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="tuya_spi_databits_t;
">Typedef <span>tuya_spi_databits_t;
</span></h4>
      <pre class="doc-declare"><code>typedef enum {
   TUYA_SPI_DATA_BIT8 = 0,
   TUYA_SPI_DATA_BIT16,
} tuya_spi_databits_t;
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="tuya_spi_cs_mode_t;
">Typedef <span>tuya_spi_cs_mode_t;
</span></h4>
      <pre class="doc-declare"><code>typedef enum {
   TUYA_SPI_CS_MODE_AUTO = 0,          // hardware auto set
   TUYA_SPI_CS_MODE_SOFT,               // software manual set
} tuya_spi_cs_mode_t;
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="tuya_spi_cfg_t;
">Typedef <span>tuya_spi_cfg_t;
</span></h4>
      <pre class="doc-declare"><code>typedef struct {
   uint8_t        cs_pin;
} tuya_spi_cfg_t;
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="tuya_spi_msg_t;
">Typedef <span>tuya_spi_msg_t;
</span></h4>
      <pre class="doc-declare"><code>typedef struct {
   void           *send_buf;
   void           *recv_buf;
   uint32_t        length;
} tuya_spi_msg_t;
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="tuya_spi_bus_cfg_t;
">Typedef <span>tuya_spi_bus_cfg_t;
</span></h4>
      <pre class="doc-declare"><code>typedef struct {
   uint8_t                  flag;
   tuya_spi_mode_t          mode;
   tuya_spi_databits_t      databits;
   tuya_spi_cs_mode_t       cs_mode;
   uint32_t                 freq_hz;
} tuya_spi_bus_cfg_t;
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="tuya_spi_bus_t">Typedef <span>tuya_spi_bus_t</span></h4>
      <pre class="doc-declare"><code>typedef struct tuya_spi_bus tuya_spi_bus_t;
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="tuya_spi_ops_t;
">Typedef <span>tuya_spi_ops_t;
</span></h4>
      <pre class="doc-declare"><code>typedef struct {
   int (*init)        (tuya_spi_bus_t *spi, tuya_spi_bus_cfg_t *cfg);
   int (*xfer)        (tuya_spi_bus_t *spi, tuya_spi_msg_t *msg);
   int (*control)     (tuya_spi_bus_t *spi, uint8_t cmd, void *arg);
   int (*deinit)      (tuya_spi_bus_t *spi);
} tuya_spi_ops_t;
</code></pre>
      <pre class="doc-comment"></pre>

      <h4 id="tuya_spi_t;
">Typedef <span>tuya_spi_t;
</span></h4>
      <pre class="doc-declare"><code>typedef struct {
   tuya_spi_cfg_t           cfg;   
   tuya_spi_bus_t           *bus;
} tuya_spi_t;
</code></pre>
      <pre class="doc-comment"></pre>
    </div>
  </body>
</html>
            